删除所有重复项,包括水平放置

时间:2018-10-06 16:17:13

标签: stata

我的数据如下:

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        dynamic scope = Activator.CreateInstance(Type.GetTypeFromProgID("LeCroy.XStreamDSO"));
    }

    public void label1_Click(object sender, EventArgs e)
    {

    }

    public void button1_Click(object sender, EventArgs e)
    {
        label2.Text = "reading back instrument ID";
        button1.Text = " 2s pause between successives commands...";
        dynamic scope = Activator.CreateInstance(Type.GetTypeFromProgID("LeCroy.XStreamDSO"));
        dynamic Replay = scope.InstrumentID;
        var Replayvalue = Replay.Value;
        var Replaytype = Replay.type;
        label1.Text = "You are connected to scope model:" + Replayvalue;
        label2.Text = "Going to recall default setup";
        dynamic CMD = scope.SaveRecall.Setup.DoRecallDefaultPanel.ActNow();
        System.Threading.Thread.Sleep(2000);
        label2.Text = "  all  Done!";
        System.Threading.Thread.Sleep(200);
        label2.Text += "\nTrigger mode Auto";
        CMD = scope.Acquisition.TriggerMode = "Auto";
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nShow measurements ";
        CMD = scope.Measure.ShowMeasure = true; // turn measure panel on
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nHorizontal scale up";
        CMD = scope.Acquisition.Horizontal.HorScaleUp.ActNow;
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nHorizontal scale up one more time..";
        CMD = scope.Acquisition.Horizontal.HorScaleUp.ActNow;
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nShow measurements statistics";
        scope.Measure.StatsOn = true;
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nTrigger mode Single";
        scope.Acquisition.TriggerMode = "Single";  //set single trigger mode 
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nclear all sweeps";
        CMD = scope.Measure.ClearSweeps;  //clear sweeps in messurements
        System.Threading.Thread.Sleep(2000);
        label2.Text += "\nTrigger mode Single...again";
        scope.Acquisition.TriggerMode = "Single";  //set single trigger mode 
        System.Threading.Thread.Sleep(2000);
        label2.Text = "\nall commands executed!";

        button1.Text = "click here to redo all...";

    }

    public void Form1_Load(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        dynamic CMD = scope.SaveRecall.Setup.DoRecallDefaultPanel.ActNow();
    }
}

我只想保留一次值,如下所示:

* Example generated by -dataex-. To install: ssc install dataex
clear
input float id strL acro
788 "SJK DFG"                        
788 "GKH DFG TYI HJK"                
788 "TYO SJK BNM"                    
832 "JKH SJK VNM ASD SJK ORY GKH EWR"
832 "DFK ASK YUR"                    
832 "ASD"                            
832 "DLW"                            
832 "IPY BNM"                        
end

这可以通过id acro 788 SJK DFG 788 GKH TYI HJK 788 TYO BNM 832 JKH SJK VNM ASD ORY GKH EWR 832 DFK ASK YUR 832 DLW 832 IPY BNM 命令完成吗?

1 个答案:

答案 0 :(得分:2)

您需要先将reshape数据转换为长格式,然后使用duplicates命令:

clear

input id strL acro 
788 "SJK DFG"          
788 "GKH DFG TYI HJK"   
788 "TYO SJK BNM"
832 "JKH SJK VNM ASD SJK ORY GKH EWR"         
832 "DFK ASK YUR"
832 "ASD"
832 "DLW"
832 "IPY BNM"      
end

split acro
drop acro

bysort id: generate i = _n
reshape long acro, i(id i)

drop if missing(acro)
duplicates drop id acro, force

接下来,您以reshape的形式编写并连接字符串变量:

reshape wide acro, i(id i)

egen acro = concat(acro*), punct(" ")
drop i acro?

list, sepby(id)

     +-----------------------------------+
     |  id                          acro |
     |-----------------------------------|
  1. | 788                       SJK DFG |
  2. | 788                   GKH TYI HJK |
  3. | 788                       TYO BNM |
     |-----------------------------------|
  4. | 832   JKH SJK VNM ASD ORY GKH EWR |
  5. | 832                   DFK ASK YUR |
  6. | 832                           DLW |
  7. | 832                       IPY BNM |
     +-----------------------------------+